package com.msr.config;

import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;


/**
 * @author tom
 * @version V1.0
 * @Package com.msr.config
 * @date 2025/1/27 9:37
 * @Copyright © 株式会社多言语系统研究所
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        OpenAPI openAPI = new OpenAPI();
        openAPI.info(new Info().title("文章管理系统")
                .description("使用springboot3-vue3等技术")
                .version("v1.0.0")
                .license(new License().name("Apache 2.0").url("https://springdoc.org")));
        openAPI.externalDocs(new ExternalDocumentation().description("项目API文档")
                .url("/"));
        // 配置 Authorize 登录鉴权
        Map<String, SecurityScheme> map = new HashMap<>();
        map.put("Authorization", new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER).name("Authorization"));
        openAPI.components(new Components().securitySchemes(map));
        map.keySet().forEach(key -> openAPI.addSecurityItem(new SecurityRequirement().addList(key)));

        return openAPI;
    }
}